﻿using System.Windows;
using System.Windows.Controls;
using WpfClient.ViewModel;

namespace WpfClient
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        /// <summary>
        /// Initializes a new instance of the MainWindow class.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            
            Closing += (s, e) => ViewModelLocator.Cleanup();      
            
        }



        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            Connexion login = new Connexion();
            login.Show();
        }
        
    

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string login = loginBox.Text;
            string password = passwordBox.Password;

            EP.Session session = new EP.Session();
            EP.RssFeedServiceClient cli = new EP.RssFeedServiceClient();
            session = cli.startSession(login, password, EP.ServiceDevice.WPF);
            if (session.status == EP.ServiceStatus.Success)
                label3.Content = "Connecté";
        }
    }
    public static class WebBrowserUtility
    {
        public static readonly DependencyProperty BindableSourceProperty =
            DependencyProperty.RegisterAttached("BindableSource", typeof(string), typeof(WebBrowserUtility), new UIPropertyMetadata(null, BindableSourcePropertyChanged));

        public static string GetBindableSource(DependencyObject obj)
        {
            return (string)obj.GetValue(BindableSourceProperty);
        }

        public static void SetBindableSource(DependencyObject obj, string value)
        {
            obj.SetValue(BindableSourceProperty, value);
        }

        public static void BindableSourcePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            
            WebBrowser browser = o as WebBrowser;
            if (browser != null)
            {
                string uri = e.NewValue as string;
                if (!string.IsNullOrEmpty(uri))
                    browser.NavigateToString(uri);
            }
        }

    }
}